from django.db import models
from role.models import SysRole


# Create your models here.菜单类
class SysMenu(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=100, unique=True, verbose_name="菜单名称")
    menu_type = models.CharField(max_length=50, verbose_name="菜单类型")
    path = models.CharField(max_length=255, null=True, verbose_name="菜单URL")
    parent_id = models.IntegerField(null=True, verbose_name="父菜单ID")
    component = models.CharField(max_length=255, null=True, verbose_name="组件路径")
    perms = models.CharField(max_length=100, null=True, verbose_name="权限标识")
    order_num = models.IntegerField(null=True, verbose_name="显示顺序")
    icon = models.CharField(max_length=100, null=True, verbose_name="菜单图标")
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="修改时间")
    remark = models.CharField(max_length=500, null=True, verbose_name="备注")
    
    def __lt__(self, other):
        return self.order_num <other.order_num
    
    class Meta:
        db_table = "sys_menu"
        
#系统角色菜单关联类
class SysRoleMenu(models.Model):
    id = models.AutoField(primary_key=True)
    role = models.ForeignKey(SysRole, on_delete=models.CASCADE, verbose_name="角色")
    menu = models.ForeignKey(SysMenu, on_delete=models.CASCADE, verbose_name="菜单")

    class Meta:
        db_table = "sys_role_menu"
